/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('cms-export', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model BatchGetRequest {
  compressionType?: string(name='CompressionType'),
  cursor?: string(name='Cursor'),
  length?: int32(name='Length'),
  metric?: string(name='Metric'),
  namespace?: string(name='Namespace'),
  recordKeyWhiteList?: string(name='RecordKeyWhiteList'),
}

model BatchGetResponseBody = {
  code?: int32(name='Code'),
  data?: {
    compressionKeys?: [ string ](name='CompressionKeys'),
    compressionValues?: [[ string ]    ](name='CompressionValues'),
    cursor?: string(name='Cursor'),
    length?: long(name='Length'),
    records?: [ 
      {
        labelValues?: [ string ](name='LabelValues'),
        labels?: [ string ](name='Labels'),
        measureLabels?: [ string ](name='MeasureLabels'),
        measureValues?: [ string ](name='MeasureValues'),
        metric?: string(name='Metric'),
        namespace?: string(name='Namespace'),
        period?: int32(name='Period'),
        tagValues?: [ string ](name='TagValues'),
        tags?: [ string ](name='Tags'),
        timestamp?: long(name='Timestamp'),
      }
    ](name='Records'),
    anchorTs?: long(name='__anchorTs__'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model BatchGetResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: BatchGetResponseBody(name='body'),
}

async function batchGetWithOptions(request: BatchGetRequest, runtime: Util.RuntimeOptions): BatchGetResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.compressionType)) {
    body['CompressionType'] = request.compressionType;
  }
  if (!Util.isUnset(request.cursor)) {
    body['Cursor'] = request.cursor;
  }
  if (!Util.isUnset(request.length)) {
    body['Length'] = request.length;
  }
  if (!Util.isUnset(request.metric)) {
    body['Metric'] = request.metric;
  }
  if (!Util.isUnset(request.namespace)) {
    body['Namespace'] = request.namespace;
  }
  if (!Util.isUnset(request.recordKeyWhiteList)) {
    body['RecordKeyWhiteList'] = request.recordKeyWhiteList;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'BatchGet',
    version = '2021-11-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function batchGet(request: BatchGetRequest): BatchGetResponse {
  var runtime = new Util.RuntimeOptions{};
  return batchGetWithOptions(request, runtime);
}

model CursorRequest {
  endTime?: long(name='EndTime'),
  matchers?: [ 
    {
      label?: string(name='Label'),
      operator?: string(name='Operator'),
      value?: string(name='Value'),
    }
  ](name='Matchers'),
  metric?: string(name='Metric'),
  namespace?: string(name='Namespace'),
  period?: int32(name='Period'),
  startTime?: long(name='StartTime'),
}

model CursorShrinkRequest {
  endTime?: long(name='EndTime'),
  matchersShrink?: string(name='Matchers'),
  metric?: string(name='Metric'),
  namespace?: string(name='Namespace'),
  period?: int32(name='Period'),
  startTime?: long(name='StartTime'),
}

model CursorResponseBody = {
  code?: int32(name='Code'),
  data?: {
    cursor?: string(name='Cursor'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model CursorResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CursorResponseBody(name='body'),
}

async function cursorWithOptions(tmpReq: CursorRequest, runtime: Util.RuntimeOptions): CursorResponse {
  Util.validateModel(tmpReq);
  var request = new CursorShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.matchers)) {
    request.matchersShrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.matchers, 'Matchers', 'json');
  }
  var body : map[string]any = {};
  if (!Util.isUnset(request.endTime)) {
    body['EndTime'] = request.endTime;
  }
  if (!Util.isUnset(request.matchersShrink)) {
    body['Matchers'] = request.matchersShrink;
  }
  if (!Util.isUnset(request.metric)) {
    body['Metric'] = request.metric;
  }
  if (!Util.isUnset(request.namespace)) {
    body['Namespace'] = request.namespace;
  }
  if (!Util.isUnset(request.period)) {
    body['Period'] = request.period;
  }
  if (!Util.isUnset(request.startTime)) {
    body['StartTime'] = request.startTime;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'Cursor',
    version = '2021-11-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function cursor(request: CursorRequest): CursorResponse {
  var runtime = new Util.RuntimeOptions{};
  return cursorWithOptions(request, runtime);
}

